﻿
/*
页面通用部分 模板 <br/>
前置条件: jquery.js, underscore.js <br/>
@author gonglong fsl 20151004
*/
var commTemplUtil = {};

commTemplUtil.type = {
    /* 1.顶部, 登陆, 注册 */
    login : "<div class='head com-w'><div class='wrapper clearfix'> " +
        "<div class='item fl'><%=welcome_txt %></div>" +
        "<div class='fr'><a href='<%=login_href %>' class='item f-red'>[登陆]</a>" +
        "<a href='<%=register_href %>' class='item'>[免费注册]</a></div></div></div>",
     /* 1.2 顶部, 登陆成功 */
    loginDone : "<div class='head com-w'><div class='wrapper clearfix'>" +
        "<div class='item fl'><%=welcome_txt %></div>" +
        "<div class='fr'>" +
        "<span class='item'><%=username %>, 您好！</span>" +
        "<a href='<%=order_href %>' class='item f-red'>[我的订单]</a>" +
        "<a href='<%=buyer_center_href %>' class='item f-red'>[采购商中心]</a>" +
        "<a href='<%=logout_href %>' class='item'>退出登陆</a></div></div></div>",
        
    /* 2.网站logo, 搜索框,二维码 */    
    search : "<div class='top-logo-line com-w'><div class='wrapper clearfix'>" + 
        "<a href='<%=home_url%>' class='logo'><img src='<%=web_logo_img%>' class='wh100'></a>" + 
        "<div class='search'><div class='search-type'>" +  
        "<span class='item f-coffee'>供应</span><span>|</span>" + 
        "<span class='item'>求购</span><span>|</span><span class='item'>商家</span></div>" +
        "<div class='search-box clearfix'><input type='text' class='text' placeholder='请输入搜索关键字'>" +
        "<input type='button' class='button' value='搜索'></div>" + 
        "<div class='hot-key'><span class='tip-txt'>热门关键字:</span>"+
        "<% _.each(hot_words, function(worditem) { %>" + 
        " <a href='<%=worditem.href_val%>' > <%=worditem.word_txt%> </a> " + 
        "<% }); %>" +
        " </div></div>" +
        "<div class='d-bar-code fr'>" + 
        "<div class='pic'><img src=' <%=d_code_img%> ' class='wh100'></div>" + 
        "<p class='txt'>APP下载</p>" + 
        " </div></div></div>",
     /* 3. 头部 导航 */ 
     headNav : "<div class='com-nav com-w'><div class='wrapper clearfix'>" + 
        "<ul class='clearfix'> "+ 
        " <% _.each(obj, function(navitem){ %> " +
        " <li><a href='<%=navitem.href_val %>' class=''><%=navitem.href_txt %></a> " + 
        " <% if(navitem.new_flag){ %> <i class='new-item'></i> <% } %> </li>" +
        "<% });  %> " +
        "</ul></div></div>",
     /* 4. 底部导航 */
     footNav : "<div class='com-w mt20'><div class='wrapper clearfix'>" + 
    "<div class='com-info-box w1200-box h150-box f12 bg-F9F9F9'>" +
    "<% _.each(obj, function(itemOut){ %><dl class='foot-info-list-item'>"+
    " <dt> <%=itemOut.item_desc%> </dt><dd>" +
    "<% _.each(itemOut.item_list ,function(itemin){ %>" +
    " <div><a href='<%=itemin.href_val%>'><%=itemin.href_txt%></a></div>" + 
    "<% }); %></dd></dl>" +
    "<% }); %></div></div></div>",
    /*6.最底部导航*/
    bottomMenu: "<div class='com-w mt20 mb20'><div class='wrapper clearfix'>" + 
    "<div class='com-info-box w1200 h160 border-none tc'><div>" +
    "<ul class='list-line w450 auto clearfix'>"+
                        "<li><a href='#'>关于我们</a></li>"+
                        "<li>|</li>"+
                        "<li><a href='#'>隐私条款</a></li>"+
                        "<li>|</li>"+
                        "<li><a href='#'>友情链接</a></li>"+
                        "<li>|</li>"+
                        "<li><a href='#'>联系我们</a></li>"+
                        "<li>|</li>"+
                        "<li><a href='#'>合作伙伴</a></li>"+
                        "<li>|</li>"+
                        "<li><a href='#'>人才招聘</a></li>"+
    "</ul></div>"+
    "<p class='lh20'>建议使用IE9.0以上版本, 1366 X 768 及以上分辨率</p>"+
                "<p class='lh20'>备案号 : 1234567890000</p>"+
                "<p class='lh20'>"+
                    "copyright 2007-2014 Coffee distribution center. All rights reserved.</p>"+
                "<div class='w250 auto clearfix'> <a href='#' class='foot-link-img'><img src='' /></a>"+
                    "<a href='#' class='foot-link-img'><img src='' /></a>"+
                    "</div></div></div></div>",
    /* 5.左侧菜单 */
    leftMenu : "<% _.each(obj , function(subMenuItem){  %>" + 
        "<dl class='sub-menu-item'><dt><i class='i-sub-menu'></i>" +
        "<span class='lbl-txt'> <%=subMenuItem.title%> </span> </dt>" +
        "<% _.each(subMenuItem.menuItems, function(menuItem){ %>" +
        "<dd><a href='<%=menuItem.href_val %>' class='link-txt'>" +
        "<span class='lbl-txt'><%=menuItem.lbl_txt %></span>" +
        "<i class='icon-caret-right'></i></a></dd>" +
        "<% }); %>" + 
        "</dl>" +
        "<% }); %> <div class='menu-bottom'></div>",

};

commTemplUtil.setTempl = function (domId, data, typeVal) {
    var templStr = commTemplUtil.type[typeVal];
    var templObj = _.template(templStr);
    var temphtml = templObj(data);
    $("#"+domId).replaceWith(temphtml);
};

commTemplUtil.addTempl = function (domId, data, typeVal) {
    var templStr = commTemplUtil.type[typeVal];
    var templObj = _.template(templStr);
    var temphtml = templObj(data);
    $("#"+domId).html(temphtml);
};

